<?php

	function sessionGET($request) {
		if (isset($_SESSION['smarthotel']['session'])) {
			header("Status: 200 Success", true, 200);
			return unserialize($_SESSION['smarthotel']['session']);
		}
		else{
			header("Status: 401 Unauthorized", true, 401);
		}
	}

	function sessionPOST($request) {
		
		$sessionJSON = json_decode(utf8_decode($request->postArgs['session']));		
		
		$session = new Session();
		$session->JSONToObject($sessionJSON);
				
		$sessionBusiness = BusinessFactory::factory('SessionBusiness');
		$session = $sessionBusiness->login($session);
		
		if ($session->getUser() != NULL) {
			
			if($session->getUser()->getUserId() != 0) {
				$_SESSION['smarthotel']['session'] = serialize($session);
				header("Status: 201 Created", true, 201);
				header("Location: " . $request->getActualUrl());
				
			} else {
				header("Status: 401 Unauthorized", true, 401);
			} 
		}
		else {
			header("Status: 500 Internal Server Error", true, 500);
		} 
	}
	
	function sessionDELETE($request) {
		unset($_SESSION['smarthotel']['session']);
		header("Status: 200 Success", true, 200);
	}
	
?>